#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
	int n, m;
	cin >> n >> m;
	vector<string> s(n);
	for (int i = 0; i < n; i++) cin >> s[i];

	set<vector<string>> set;

	for (int i = 0; i < n - m + 1; i++) for (int j = 0; j < n - m + 1; j++) {
		vector<string> tmp;
		for (int ii = i; ii < i + m; ii++) tmp.push_back(s[ii].substr(j, m));
		set.insert(tmp);
	}

	cout << set.size() << endl;
	return 0;
}